<template>
    <div class="broadCast-woman">
        <el-form :inline="true" :model="formInline">
            <el-form-item label="昵称：">
                <el-input v-model="formInline.nickname" placeholder="关键字ID"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="search">搜索</el-button>
                <el-button type="primary" @click="reset">重置</el-button>
            </el-form-item>
        </el-form>
        <el-table
            :header-cell-style="{color:'#555555'}"
            class="black"
            :data="tableData"
            stripe
            border
            style="width: 100%">
            <el-table-column
                prop="id"
                label="ID"
                align="center">
            </el-table-column>
            <el-table-column
                prop="createTime"
                label="发布时间"
                align="center">
            </el-table-column>
            <el-table-column
                prop="userId"
                label="用户ID"
                align="center">
            </el-table-column>
            <el-table-column
                prop="nickname"
                label="昵称"
                align="center">
            </el-table-column>
            <el-table-column
                prop="identity"
                label="认证"
                align="center">
                <template slot-scope="scope">
                {{scope.row.identity == 2?'已认证':'未认证'}}
                </template>
            </el-table-column>
            <el-table-column
                label="约会时间"
                align="center">
                <template slot-scope="scope">
                {{scope.row.date}}{{scope.row.time}}
                </template>
            </el-table-column>
            <el-table-column
                prop="city"
                label="约会城市"
                align="center">
            </el-table-column>
            <el-table-column
                prop="datingMoney"
                label="约会金额"
                align="center">
            </el-table-column>
            <el-table-column
                label="报名人数"
                align="center">
                <template slot-scope="scope">
                <span>{{scope.row.signerNum}}</span>
                <span class="signerList" @click="onNameClick(scope.row)">名单</span>
                </template>
            </el-table-column>
            <el-table-column
                prop="isDeleted"
                label="状态"
                align="center">
                <template slot-scope="scope">
                {{scope.row.isDeleted == 0?'生效':(scope.row.isDeleted == 1?'用户已删除':'运营已删除')}}
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="160">
                <template slot-scope="scope">
                <el-button @click="onDetailClick(scope.row)" size="small">详情</el-button>
                <el-button @click="onDelClick(scope.row)" size="small">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="footer-page">
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="page_size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total_page">
        </el-pagination>
        </div>
        <el-dialog
            title="提示"
            :visible.sync="dialogVisible"
            width="30%">
            <span>确认删除吗？</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="onSureClick">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: 'broadCast-woman',
    data () {
        return {
            dialogVisible: false,
            del_station_id: '',
            list_params: {
                id: '',
                nickname: '',
                page: 1,
                page_size: 10
            },
            page: 1,
            page_size: 10,
            total_page: 0,
            formInline: {
                nickname: ''
            },
            tableData: []
        }
    },
    created () {
        // this.tableData = []
    },
    mounted () {
        // 进来页面获取课程
        let params = {}
        params['page'] = 1
        params['size'] = 10
        let data = {
            params: params
        }
        this.getListBySex(1, data) // 1表示女性
    },
    methods: {
        onAddKeywordClick () {
            this.$router.push({
                name: 'monitorSet.keyword.sourceAdd',
                params: {
                    // course_id: this.courseList[index].id
                }
            })
        },
        search () {
            this.page = 1
            const params = {
                params: {
                    page: this.page,
                    size: this.page_size,
                    nickname: this.formInline.nickname
                }
            }
            // 进来页面获取课程
            this.getListBySex(1, params) // 1表示女性
        },
        reset () {
            this.formInline = {
                station_id: '',
                station_name: '',
                station_url: '',
                station_state: '',
                station_code: ''
            }
        },
        onNameClick (row) {
            this.$router.push({
                name: 'broadCast.signName',
                params: {
                    id: row.id,
                    release_name: row.nickname
                }
            })
        },
        onDetailClick (row) {
            // alert(row.id)
            this.$router.push({
                name: 'broadCast.detail',
                params: {
                    id: row.id
                }
            })
        },
        onDelClick (item) {
            this.dialogVisible = true
            this.del_id = item.userId
        },
        onSureClick () {
            this.dialogVisible = false
            this.deleteData(this.del_id)
        },
        onLimitClick () {
            console.log('禁用')
        },
        handleSizeChange (val) {
            this.page_size = val
            const params = {
                params: {
                    page: this.page,
                    size: val
                }
            }
            this.getListBySex(1, params)
        },
        handleCurrentChange (val) {
            this.page = val
            const params = {
                params: {
                    page: val,
                    size: this.page_size
                }
            }
            this.getListBySex(1, params)
        },
        getListBySex (sex, data) {
            this.$api.broadCast.getListBySex(sex, data, res => {
                // 隐藏加载动画
                // this.$vux.loading.hide()
                if (res.code === 200) {
                    this.tableData = res.data.list
                    this.total_page = res.data.totalCount
                    this.page = res.data.currPage
                    this.page_size = res.data.pageSize
                }
            })
        },
        getDetail (list) {
            let data = list || []
            let newArry = []
            for (let i = 0; i < data.length; i++) {
                newArry.push({
                    id: data[i].id || ''
                })
                if (i === data.length - 1) {
                    return newArry
                }
            }
        },
        deleteData (id) {
            this.$api.broadCast.deleteBroadcast(id, res => {
                // 隐藏加载动画
                // this.$vux.loading.hide()
                if (res.code === 200) {
                    this.$message({
                        message: '删除成功',
                        type: 'success'
                    })
                    const params = {
                        params: {
                            page: this.page,
                            size: this.page_size
                        }
                    }
                    this.getListBySex(1, params)
                }
            })
        }
    }
}
</script>

<style lang="less" scoped>
.broadCast-woman {
    position: relative;
    width: 100%;
    height: 100%;
    .margin-bottom-12 {
        margin-bottom: 10px;
    }
    .el-row {
        margin-bottom: 20px;
        &:last-child {
        margin-bottom: 0;
        }
    }
    .el-col {
        border-radius: 4px;
    }
    .grid-content {
        position: relative;
        height: 40px;
    }
    .grid-padding {
        /* padding-left: 20px; */
        padding-right: 20px;
    }
    .grid-title {
        float: left;
        width: 72px;
        height: 40px;
        line-height: 40px;
        font-size: 14px;
        color: #333;
        text-align: center;
    }
    .grid-input {
        float: left;
        width: 130px;
        height: 40px;
        line-height: 40px;
        font-size: 14px;
        color: #333;
        text-align: center;
    }
    .row-bg {
        padding: 10px 0;
        background-color: #f9fafc;
    }
    .footer-page {
        width: 540px;
        // margin: 0 auto;
        padding-top: 20px;
    }
    .signerList {
        color: #6da0f0;
        &:hover {
            cursor: pointer;
        }
    }
}
</style>
